<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('模型列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								模型标识：<input type="text" name="key"/>
							</li>
							<li>
								模型名称：<input type="text" name="name"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-warning" onclick="$.modal.open('新建模型', '/model/manage/add', '780', '400');">
					<i class="fa fa-plus"></i> 新建模型
				</a>
			</div>
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "model/manage";
		$(function() {
		    var options = {
		        url:  "/model/manage/modelLists",
				removeUrl: "/model/manage/remove/{id}",
		        sortName: "modelSort",
		        modalName: "模型",
		        columns: [{
		            checkbox: true
		        },
				{
					field: 'id',
					title: '模型编号',
					visible: false
				},
				{
					field: 'deploymentId',
					title: '部署编号',
					visible: false
				},
				{
					field: 'key',
					title: '模型标识',
					sortable: true
				},
		        {
		            field: 'name',
		            title: '模型名称',
		            sortable: true
		        },
		        {
		            field: 'category',
		            title: '分类'
		        },
				{
					field: 'version',
					title: '版本'
				},
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-warning btn-xs" target="_blank" href="/designer/index.html#/editor/' + row.id + '"><i class="fa fa-edit"></i>设计</a> ');
						if (row.deploymentId == null) {
							actions.push('<a class="btn btn-success btn-xs" href="#" onclick="deploy(\'' + row.id + '\')"><i class="fa fa-location-arrow"></i>发布</a> ');
						}
						actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0);" onclick="exportXml(\'' + row.key + '\',\'' + row.id + '\');return false"><i class="fa fa-mail-forward"></i>导出</a> ');
						actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
					}
		        }]
		    };
		    $.table.init(options);
		});

		function deploy(modelid) {
			$.operate.get(prefix + "/deploy/" + modelid, function (data){
				$.modal.alert(data.msg);
			});
		}

		function exportXml(key, id) {
			if (!id)return;
			const a = document.createElement("a");
			a.href = prefix + "/export/" + id;
			// 这里设置下载的名字
			a.download = key + ".bpmn20.xml";
			a.click();
		}
	</script>
</body>
</html>